use TableD6_MSAR_ADL_updatingestimates.dta , clear
format date %tq
tsset date 
tsfill
sort date
merge 1:1 date using "statespacedata.dta"
drop if _merge==2

gen month=month(dofq(date))
gen year=year(dofq(date))

gen twoyearcycle = floor((year-1953)/2)+1

sort twoyearcycle
by twoyearcycle: gen counter=_n

sort date
gen ics = abs(partyics)
gen begics = ics if counter==1
gen endics = ics if counter==8

gen presapprove = abs(partyapprove)
gen begapprove = presapprove if counter==1
gen endapprove = presapprove if counter==8


sort twoyearcycle
by twoyearcycle: egen meanbegics = mean(begics)
by twoyearcycle: egen meanendics = mean(endics)
by twoyearcycle: egen meanbegapprove = mean(begapprove)
by twoyearcycle: egen meanendapprove = mean(endapprove)

gen diffics = abs(meanendics-meanbegics)
gen diffapprove = abs(meanendapprove-meanbegapprove)

sort date
gen preselect = 0
replace preselect = 1 if twoyearcycle/2 == floor(twoyearcycle/2)

drop if counter!=1

reg avgfsd fpartyideochange  
reg avgfsd fpartyagendachange  
reg avgfsd fpartyideochange fpartyagendachange 
estat szroeter, rhs 
estat szroeter, rhs mtest(b)

reg avgfsd fpartyideochange fpartyagendachange diffics diffapprove

